import { reactive } from "vue";
import type { FormRules } from "element-plus";
import { isPhone } from "@pureadmin/utils";

/** 自定义表单规则校验 */
export const formRules = reactive(<FormRules>{
	supplierName: [{ required: true, message: "供应商名称为必填项", trigger: "blur" }],
	contactName: [{ required: true, message: "联系人姓名为必填项", trigger: "blur" }],
  supplierCode: [{ required: true, message: "供应商编码为必填项", trigger: "blur" }],
	contactPhone: [{ required: true, message: "联系电话为必填项", trigger: "blur" },
	{
		validator: (rule, value, callback) => {
			if (value === "") {
				callback();
			} else if (!isPhone(value)) {
				callback(new Error("请输入正确的手机号码格式"));
			} else {
				callback();
			}
		},
		trigger: "blur"
	}],
});
